iT邦幫忙

2

寫了3年代碼後,我寫一個簡單的api長這樣了,請忽略註釋的長度

  • 分享至 

  • xImage
  •  
def raceRaceSettingInfo(request):
    '''
    api to get race setting info
    fograce : 
    會長姓名,鴿會名稱 : query from fogboss and fogorg by "orgid"
    賽程名稱 : "scheduleid" from fogschedule
    比賽名稱 : "racetitle"
    比賽時間 : "time"
    軌跡點合法日期-起始 : "starttime"
    軌跡點合法日期-結束 : "endtime"
    參賽鴿主人數 : count(*) from fogownner
    參賽鴿數 : count(*) from fogdove
    參賽鴿舍數 : count(distinct(dovecoteid)) from fogdove
    放飛地:"releaseposition"
    歸返地:"arrivalposition"
    備註:"note"
            Parameters:

            Returns:
                    raceinfo:
                        基本資料:
                        會長姓名,鴿會名稱,賽程名稱,比賽名稱,比賽時間,
                        軌跡點合法日期-起始,軌跡點合法日期-結束,
                        參賽鴿主人數,參賽鴿數,參賽鴿舍數,放飛地,歸返地,備註
    '''     
    if request.method == 'POST':
        raceInfo = {
            "bossname":"","orgname":"","schedulename":"","racetitle":"","time":"",
            "starttime":"","endtime":"",
            "ownerCount":"","doveCount":"","doveCoteCount":"","releaseposition":"","arrivalposition":"","note":""
        }
        tmpraceInfo = Fograce.objects.values_list("orgid","scheduleid","racetitle","time","starttime","endtime","releaseposition","arrivalposition","note")[0]
        # print(tmpraceInfo)
        if len(tmpraceInfo) == 0 :
            return JsonResponse({'raceInfo':''})
        (orgid,scheduleid,racetitle,time,starttime,endtime,releaseposition,arrivalposition,note) = tmpraceInfo
        # print(orgid,scheduleid,racetitle,time,starttime,endtime,releaseposition,arrivalposition,note)
        bossid,orgname = Fogorg.objects.filter(orgid=orgid).values_list("bossid","orgname")[0]
        # print(bossid,orgname)
        bossname = Fogboss.objects.filter(bossid=bossid).values_list("name")[0][0]
        # print(bossname)
        schedulename = Fogschedule.objects.filter(scheduleid=scheduleid).values_list("scheduletitle")[0][0]
        # print(schedulename)
        ownerCount = Fogowner.objects.count()
        # print(ownerCount)
        doveCount = Fogdove.objects.count()
        # print(doveCount)
        doveCoteCount = Fogdove.objects.values('dovecoteid').distinct().count()
        # print(doveCoteCount)
        

        raceInfo["bossname"]=bossname
        raceInfo["orgname"]=orgname
        raceInfo["schedulename"]=schedulename
        raceInfo["racetitle"]=racetitle
        raceInfo["time"]=time
        raceInfo["starttime"]=starttime
        # print(raceInfo)
        raceInfo["endtime"]=endtime
        raceInfo["ownerCount"]=ownerCount
        raceInfo["doveCount"]=doveCount
        raceInfo["doveCoteCount"]=doveCoteCount
        raceInfo["releaseposition"]=releaseposition
        raceInfo["arrivalposition"]=arrivalposition
        raceInfo["note"]=note
        # print(raceInfo)

        return JsonResponse({'raceInfo':raceInfo})

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言